<?php
include("../common.inc.php");
InitGP(array("page","action","aid","delids")); //初始化变量全局返回
include("function_common.php");
//初始化对象
include(INC_PATH."/referrals.class.php");
$rf=new Referralsclass();

if(empty($action)){
	InitGP(array("uname","tid")); //初始化变量全局返回
	if(!empty($uname))$wherestr[]="uname like '%{$uname}%'";
	if(isset($tid))$wherestr[]="state in({$tid})";
	if(!empty($wherestr)) $wheresql = implode(' AND ', $wherestr);	//条件汇总
	
	//获取当前页码
	$total=$rf->getcount($wheresql); 							  //总信息数
	$pagesize=15;												  //一页显示信息数
	$page = isset($page) ? max(1, intval($page)) : 1;             //处理页码变量
	$offset=($page-1)*$pagesize;   								  //偏移量
	$dataarray=$rf->getdata("$offset,$pagesize",$wheresql); //获取团购数据
	
	//包含后台模板文件
	include("tpl/accountreferrals_list.htm");
}elseif ($action=="lose") {
		//更新状态禁用这次返利
	InitGP(array("aid")); //初始化变量全局返回
	if(GetNum($aid)){
	$rf->editstate($aid,2);
	showmsg("设置返利失效状态成功!","accountreferrals_list.php");//成功
	}else showmsg("缺少参数 操作失败!","accountreferrals_list.php");//失败
}elseif ($action=="check") {
		//更新状态禁用或者启用
	InitGP(array("aid")); //初始化变量全局返回
	if(GetNum($aid)){
		//执行返利操作
		$info=$rf->check($aid);
		if($info)showmsg("返利成功!","accountreferrals_list.php");//成功
		else showmsg("操作失败!","accountreferrals_list.php");//失败
	}else showmsg("缺少参数 操作失败!","accountreferrals_list.php");//失败
	
}elseif ($action=="del" && !empty($aid)){
	//执行删除操作
	$aid=GetNum($aid);
	$info=$rf->del($aid);
	if($info=="OK")showmsg("删除返利单成功！","accountreferrals_list.php");
	else showmsg($info,"accountreferrals_list.php");
}elseif ($action=="dels"){
	if(empty($delids)){showmsg("没有选择任何对象！","accountreferrals_list.php");exit;}//空选择
	//执行删除多个操作
	foreach ($delids as $id){
		$id=GetNum($id);
		$info=$rf->del($id);
	}
	if($info=="OK")showmsg("删除返利单成功！","accountreferrals_list.php");
	else showmsg($info,"accountreferrals_list.php");
}

?>

